import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/afterSales/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询详情'
});
const addDesc = formatMessage({
    id: 'api.message.addDesc',
    defaultMessage: '新增'
});
const updateDesc = formatMessage({
    id: 'api.message.updateDesc',
    defaultMessage: '修改'
});
const submitDesc = formatMessage({
    id: 'api.message.submitDesc',
    defaultMessage: '提交'
});
const confirmDesc = formatMessage({
    id: 'api.message.confirmDesc',
    defaultMessage: '确认'
});
const upInvoiceDesc = formatMessage({
    id: 'api.message.upInvoiceDesc',
    defaultMessage: '上传发票'
});
const invoiceConfirmDesc = formatMessage({
    id: 'api.message.invoiceConfirmDesc',
    defaultMessage: '发票确认'
});
const writeOffDesc = formatMessage({
    id: 'api.message.writeOffDesc',
    defaultMessage: '核销'
});
const abandonDesc = formatMessage({
    id: 'api.message.abandonDesc',
    defaultMessage: '作废'
});
const getMarketingActivityListDesc = formatMessage({
    id: 'api.message.getMarketingActivityListDesc',
    defaultMessage: '查询营销活动'
});
const getTechnologyActivityDetailListDesc = formatMessage({
    id: 'api.message.getTechnologyActivityListDesc',
    defaultMessage: '查询技术升级'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/marketingActivityReport/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/marketingActivityReports/forCurrentUser?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/marketingActivityReports/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
// 新增
export const addApplyReport = data => request(`${baseUrl}/marketingActivityReports`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, addDesc));
//修改
export const updateApplyReport = (id, data) => request(`${baseUrl}/marketingActivityReports/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, updateDesc));
// 提报
export const submitData = (id, rowVersion) => request(`${baseUrl}/marketingActivityReports/${id}/submit`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({
        rowVersion
    })}).then(handleFetchResultNotification(REQUEST_TYPE.submit, submitDesc));
// 确认
export const confirmData = (id, data) => request(`${baseUrl}/marketingActivityReports/${id}/confirm`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, confirmDesc));
// 上传发票
export const upInvoiceData = (id, data) => request(`${baseUrl}/marketingActivityReports/${id}/upInvoice`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, upInvoiceDesc));
// 发票确认
export const invoiceConfirmData = (id, data) => request(`${baseUrl}/marketingActivityReports/${id}/invoiceConfirm`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, invoiceConfirmDesc));
// 核销
export const writeOffData = (id, data) => request(`${baseUrl}/marketingActivityReports/${id}/writeOff`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, writeOffDesc));
// 作废
export const abandonData = (id, rowVersion) => request(`${baseUrl}/marketingActivityReports/${id}/abandon`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({
        rowVersion
    })}).then(handleFetchResultNotification(REQUEST_TYPE.submit, abandonDesc));
// 营销活动查询
export const getMarketingActivity = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/marketingActivityDeclares/forMarketingActivityReports?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getMarketingActivityListDesc));
};
// 营销活动快捷查询
export const getMarketingActivitySimple = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/marketingActivityDeclares/forMarketingActivityReports/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getMarketingActivityListDesc));
};
// 技术升级车辆清单查询
export const getTechnologyActivityDetail = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/technologyActivityVehicles/forTechnologyActivityClaims?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getTechnologyActivityDetailListDesc));
};
